//
// Created by wenyaxi on 24-11-14.
//
#include <common.h>

class Solution {
public:
    int maxIceCream(vector<int> &costs, int coins) {
        int idx = 0, cnt = 0;
        ranges::sort(costs, less<>());
        while (coins > 0 && idx < costs.size()) {
            if (costs[idx] == 0) {
                idx++;
                cnt++;
            }
            int min_val = min(costs[idx], coins);
            coins -= min_val;
            costs[idx] -= min_val;
        }
        while (idx < costs.size()) {
            if (costs[idx] == 0) {
                idx++;
                cnt++;
            } else {
                break;
            }
        }
        return cnt;
    }
};

int main() {
    Solution s;
    vector costs = {11};
    constexpr int coins = 12;
    cout << s.maxIceCream(costs, coins) << endl;
    return 0;
}
